package com.huawei.appgallery.purchasehistory.ui.activity;

import android.app.ActionBar;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.service.common.protocol.request.AppListFragmentRequest;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.FixViewPager;
import com.huawei.appgallery.purchasehistory.api.AppTracesListFragmentProtocol;
import com.huawei.appgallery.purchasehistory.api.AppTracesListFragmentProtocol.Request;
import com.huawei.appgallery.purchasehistory.api.IPurchaseHistoryProtocol;
import com.huawei.appgallery.purchasehistory.api.bean.FamilyMemberResponseBean;
import com.huawei.appgallery.purchasehistory.ui.fragment.ProductFragment;
import com.huawei.appgallery.purchasehistory.ui.fragment.PurchaseHorizontalMultiTabsFragment;
import com.huawei.appgallery.purchasehistory.ui.protocol.PurchaseHistoryFamilyShareProtocol;
import com.huawei.appgallery.purchasehistory.ui.protocol.PurchaseHistoryProtocol;
import com.huawei.appgallery.purchasehistory.ui.widget.ToolBarIcon;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.hmf.annotation.ActivityDefine;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import huawei.widget.HwSubTabWidget;
import huawei.widget.HwSubTabWidget.b;
import java.lang.ref.WeakReference;
import o.azb;
import o.ccz;
import o.cfw;
import o.cgv;
import o.cip;
import o.ciy;
import o.cjk;
import o.cjm;
import o.cjo;
import o.SomeFragmentStateAdapter;
import o.csp;
import o.css;
import o.cst.a;
import o.cst.d;
import o.cst.f;
import o.cst.h;
import o.csv;
import o.cti;
import o.ctj;
import o.ctm;
import o.ctn;
import o.cto;
import o.ctp;
import o.BaseRequest;
import o.dgh;
import o.dgm;
import o.ContentManager;
import o.epv;
import o.eqp;
import o.eua;
import o.ActivityUtil;
import o.evx;
import o.fiv;
import o.FragmentManager;
import o.FragmentTransaction;
import org.jetbrains.annotations.NotNull;

@ActivityDefine(alias = "purchaseHistoryActivity", protocol = IPurchaseHistoryProtocol.class)
public class PurchaseHistoryActivity extends PurchaseMenuActivity<PurchaseHistoryProtocol> implements OnClickListener, cto, ctm, b, ctj {
    private fiv ʿ = fiv.ॱ(this);
    private final BroadcastReceiver ˈ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ PurchaseHistoryActivity ˎ;

        {
            this.ˎ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if ("com.huawei.hwid.ACTION_REMOVE_ACCOUNT".equals(intent.getAction())) {
                this.ˎ.finish();
            }
        }
    };
    private HwSubTabWidget ˉ;
    private String ˊˊ = UserSession.getInstance().getUserId();
    private String ˊˋ = eqp.ॱ();
    protected ToolBarIcon ˊॱ;
    private ContractFragment ˊᐝ;
    private ContractFragment ˋˊ;
    private cip ˋˋ;
    protected String ˋॱ = "";
    private int ˍ;
    protected String ˏॱ = "";
    protected ToolBarIcon ͺ;
    protected ToolBarIcon ॱˊ;

    class c extends SomeFragmentStateAdapter {
        final /* synthetic */ PurchaseHistoryActivity ˊ;
        Fragment ˏ;

        c(PurchaseHistoryActivity purchaseHistoryActivity, FragmentManager juVar) {
            this.ˊ = purchaseHistoryActivity;
            super(juVar);
        }

        @NotNull
        public Object instantiateItem(ViewGroup viewGroup, int i) {
            ContractFragment contractFragment = (ContractFragment) super.instantiateItem(viewGroup, i);
            if (i == 0) {
                this.ˊ.ˊᐝ = contractFragment;
            } else if (i == 1) {
                this.ˊ.ˋˊ = contractFragment;
            }
            return contractFragment;
        }

        public Fragment getItem(int i) {
            String userId = UserSession.getInstance().getUserId();
            cjo appTracesListFragmentProtocol = new AppTracesListFragmentProtocol();
            switch (i) {
                case 0:
                    AppListFragmentRequest request = new Request();
                    request.ॱ(0);
                    request.ˋॱ(userId);
                    request.ʽ(false);
                    appTracesListFragmentProtocol.ˏ(request);
                    this.ˊ.ˊᐝ = (ContractFragment) cjk.ˎ().ˊ(new cjm("apptracealllist.fragment", appTracesListFragmentProtocol));
                    if (this.ˊ.ˊᐝ == null) {
                        csp.ˏ.ˋ("PurchaseTAG", "fragmentAll == null");
                        this.ˊ.ˊᐝ = new ContractFragment();
                    }
                    return this.ˊ.ˊᐝ;
                case 1:
                    AppListFragmentRequest request2 = new Request();
                    request2.ॱ(1);
                    appTracesListFragmentProtocol.ˏ(request2);
                    this.ˊ.ˋˊ = (ContractFragment) cjk.ˎ().ˊ(new cjm("product.fragment", appTracesListFragmentProtocol));
                    if (this.ˊ.ˋˊ == null) {
                        this.ˊ.ˋˊ = new ContractFragment();
                    }
                    return this.ˊ.ˋˊ;
                default:
                    return new ContractFragment();
            }
        }

        public int getCount() {
            return this.ˊ.ˉ.ॱ();
        }

        public void setPrimaryItem(ViewGroup viewGroup, int i, Object obj) {
            super.setPrimaryItem(viewGroup, i, obj);
            Fragment fragment = (Fragment) obj;
            if (fragment != this.ˏ) {
                this.ˏ = fragment;
                this.ˊ.ˊˋ();
            }
        }

        Fragment ॱ() {
            return this.ˏ;
        }
    }

    static class e implements IServerCallBack {
        private WeakReference<PurchaseHistoryActivity> ˏ;

        e(PurchaseHistoryActivity purchaseHistoryActivity) {
            this.ˏ = new WeakReference(purchaseHistoryActivity);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            PurchaseHistoryActivity purchaseHistoryActivity = (PurchaseHistoryActivity) this.ˏ.get();
            if (purchaseHistoryActivity != null && !purchaseHistoryActivity.isFinishing()) {
                if (responseBean.getResponseCode() != 0 || responseBean.getRtnCode_() != 0) {
                    csv.ˋ().ʽ();
                } else if (responseBean instanceof FamilyMemberResponseBean) {
                    FamilyMemberResponseBean familyMemberResponseBean = (FamilyMemberResponseBean) responseBean;
                    if (familyMemberResponseBean.getResponseCode() == 0) {
                        csv.ˋ().ॱ(familyMemberResponseBean.ˎ());
                    } else {
                        csp.ˏ.ˊ("PurchaseTAG", "response error=" + familyMemberResponseBean.getResponseCode());
                    }
                }
                ˎ(purchaseHistoryActivity.ˋˋ);
                purchaseHistoryActivity.ˋᐝ();
            }
        }

        private void ˎ(cip o_cip) {
            if (o_cip != null) {
                o_cip.ॱ(8);
            }
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(d.ᐝ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(a.ʼ));
        cgv.ˋ(this, a.ॱ, a.ˊ);
        ˎˎ();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.hwid.ACTION_REMOVE_ACCOUNT");
        ActivityUtil.registerReceiver(this, intentFilter, this.ˈ);
        ˍ();
        ˋˋ();
        ˊᐝ();
        ˋˊ();
        cfw.ˎ(css.ॱ(ccz.ॱ()), new e(this));
        csv.ˋ().ˏ(true);
    }

    private void ˊᐝ() {
        if (this.ˋˋ == null) {
            this.ˋˋ = new cip();
            this.ˋˋ.ˎ(findViewById(o.cst.e.ᐝˊ));
        }
        this.ˋˋ.ॱ(0);
    }

    private void ˋˊ() {
        if (eqp.ᐝ() && eua.ˏ().ˏ("is_first_enter_ purchase_history_activity", true)) {
            cjk.ˎ().ˋ(this, new cjm("PurchaseHistoryGuideActivity.activity", null));
        }
    }

    private void ˎˎ() {
        ˎ((IPurchaseHistoryProtocol) this.ʿ.ॱ());
    }

    public void ˎ(ctn o_ctn) {
        this.ॱˎ.add(o_ctn);
    }

    public void ˊ(ctn o_ctn) {
        this.ॱˎ.remove(o_ctn);
    }

    private void ˋᐝ() {
        this.mFixViewPager = (FixViewPager) findViewById(o.cst.e.ـ);
        this.ˉ = (HwSubTabWidget) findViewById(o.cst.e.ˊˋ);
        ˌ();
        this.mFixViewPager.setOnPageChangeListener(new cti(this.ˉ, this));
        this.mFixViewPager.setAdapter(new c(this, ˏॱ()));
        this.mFixViewPager.setCurrentItem(this.ˍ);
        ˏ(csv.ˋ().ˎ());
        ˊ(false);
    }

    private void ˋˋ() {
        this.ᐝॱ = findViewById(o.cst.e.ˋॱ);
        this.ͺ = (ToolBarIcon) findViewById(o.cst.e.ˊ);
        this.ͺ.setOnClickListener(this);
        this.ˊॱ = (ToolBarIcon) findViewById(o.cst.e.ʽ);
        this.ˊॱ.setOnClickListener(this);
        this.ॱˊ = (ToolBarIcon) findViewById(o.cst.e.ʼ);
        this.ॱˊ.setOnClickListener(this);
    }

    private void ˏ(boolean z) {
        int i = z ? 3 : 2;
        ˊ(i, this.ͺ);
        ˊ(i, this.ˊॱ);
        if (z) {
            ˊ(i, this.ॱˊ);
        }
    }

    private void ˊ(int i, ToolBarIcon toolBarIcon) {
        if (toolBarIcon == null) {
            csp.ˏ.ˏ("PurchaseTAG", "toolbar == null");
            return;
        }
        int ˊ = epv.ˊ(this, i);
        LayoutParams layoutParams = (LayoutParams) toolBarIcon.getLayoutParams();
        layoutParams.gravity = 17;
        layoutParams.width = ˊ;
        toolBarIcon.setLayoutParams(layoutParams);
        toolBarIcon.setOnClickListener(this);
    }

    private void ˍ() {
        View findViewById = findViewById(o.cst.e.ᐝᐝ);
        azb.ˏ(findViewById);
        this.ʻॱ = findViewById.findViewById(o.cst.e.ॱʻ);
        ˏ(findViewById);
        LinearLayout linearLayout = (LinearLayout) findViewById.findViewById(o.cst.e.ᐝॱ);
        linearLayout.setOnClickListener(this);
        linearLayout.setVisibility(0);
        ((LinearLayout) findViewById.findViewById(o.cst.e.ˏॱ)).setOnClickListener(this);
        ((LinearLayout) findViewById.findViewById(o.cst.e.ͺ)).setOnClickListener(this);
        ((LinearLayout) findViewById(o.cst.e.ˊॱ)).setOnClickListener(this);
        ActionBar actionBar = getActionBar();
        ((TextView) findViewById.findViewById(o.cst.e.ᐝˋ)).setText(ॱˊ());
        if (actionBar != null) {
            actionBar.hide();
        }
    }

    protected void ˊ(boolean z) {
        if (z) {
            cgv.ˋ(this, a.ॱ, a.ˊ);
        } else {
            cgv.ˋ(this, a.ॱ, a.ʼ);
        }
        if (!z) {
            this.ᐝॱ.setVisibility(8);
            this.ʻॱ.setVisibility(8);
        } else if (getApplicationContext().getResources().getConfiguration().orientation == 2) {
            this.ᐝॱ.setVisibility(8);
            this.ʻॱ.setVisibility(0);
            ᐝॱ();
        } else {
            this.ᐝॱ.setVisibility(0);
            this.ʻॱ.setVisibility(8);
            ʼॱ();
        }
    }

    protected void ˏ(Menu menu) {
    }

    protected String ॱˊ() {
        return getString(h.ˊˊ);
    }

    private void ˏ(View view) {
        view.findViewById(o.cst.e.ᐧ).setOnClickListener(new evx(this) {
            final /* synthetic */ PurchaseHistoryActivity ˋ;

            {
                this.ˋ = r1;
            }

            public void ˋ(View view) {
                this.ˋ.onBackPressed();
            }
        });
    }

    private void ˌ() {
        String[] ͺ = ͺ();
        this.ˉ.ˎ();
        if (this.ˍ < 0 || this.ˍ >= ͺ.length) {
            this.ˍ = 0;
        }
        int length = ͺ.length;
        for (int i = 0; i < length; i++) {
            boolean z;
            HwSubTabWidget hwSubTabWidget = this.ˉ;
            hwSubTabWidget.getClass();
            HwSubTabWidget.a aVar = new HwSubTabWidget.a(hwSubTabWidget, ͺ[i], this);
            aVar.ˎ(i);
            HwSubTabWidget hwSubTabWidget2 = this.ˉ;
            if (i == this.ˍ) {
                z = true;
            } else {
                z = false;
            }
            hwSubTabWidget2.ॱ(aVar, z);
        }
    }

    protected String[] ͺ() {
        return new String[]{this.ˏॱ, getString(h.ͺ)};
    }

    public void onDestroy() {
        super.onDestroy();
        ActivityUtil.unregisterReceiver((Context) this, this.ˈ);
        csv.ˋ().ˏ(false);
    }

    public void ˊ(HwSubTabWidget.a aVar, FragmentTransaction kaVar) {
        if (this.mFixViewPager != null) {
            c cVar = (c) this.mFixViewPager.getAdapter();
            if (cVar != null) {
                Fragment ॱ = cVar.ॱ();
                if (ॱ instanceof ciy) {
                    ((ciy) ॱ).ʾॱ();
                }
            }
        }
    }

    public void ˎ(HwSubTabWidget.a aVar, FragmentTransaction kaVar) {
        if (this.ˉ != null) {
            int ˊ = this.ˉ.ˊ();
            if (this.mFixViewPager != null) {
                this.mFixViewPager.setCurrentItem(ˊ);
            }
        }
    }

    public void ॱ(HwSubTabWidget.a aVar, FragmentTransaction kaVar) {
    }

    protected int ᐝ() {
        return f.ˎ;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        } else if (itemId == o.cst.e.ˊ) {
            dgh.ॱ((Context) this, getString(h.ˊ), "02" + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˊ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˋ);
            ˎ(true);
            return true;
        } else if (itemId == o.cst.e.ʽ) {
            dgh.ॱ((Context) this, getString(h.ˊ), "03" + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˊ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˋ);
            ˎ(false);
            return true;
        } else if (itemId != o.cst.e.ᐝ) {
            return super.onOptionsItemSelected(menuItem);
        } else {
            ॱ((Activity) this);
            return true;
        }
    }

    private void ˎ(boolean z) {
        if (this.mFixViewPager == null) {
            csp.ˏ.ˏ("PurchaseTAG", "viewpager == null");
            return;
        }
        int ˋ = this.mFixViewPager.getCurrentItem();
        ContractFragment contractFragment = null;
        if (ˋ == 0) {
            contractFragment = this.ˊᐝ;
        } else if (ˋ == 1) {
            contractFragment = this.ˋˊ;
        }
        if (contractFragment instanceof ctp) {
            ctp o_ctp = (ctp) contractFragment;
            if (z) {
                o_ctp.ˊʻ();
                return;
            } else {
                o_ctp.ٴ();
                return;
            }
        }
        csp.ˏ.ˏ("PurchaseTAG", "fragment not instanceof PurchaseJumper");
    }

    private void ॱ(Activity activity) {
        cjo purchaseHistoryFamilyShareProtocol = new PurchaseHistoryFamilyShareProtocol();
        purchaseHistoryFamilyShareProtocol.ˋ(new PurchaseHistoryFamilyShareProtocol.Request());
        cjk.ˎ().ˋ(activity, new cjm("app.family.share.activity", purchaseHistoryFamilyShareProtocol));
    }

    public void ˎ(int i) {
        if (i == 0) {
            ˋ(this.ˊᐝ);
        } else if (i == 1) {
            ˋ(this.ˋˊ);
        } else {
            ˊ(false);
        }
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id == o.cst.e.ˊ || id == o.cst.e.ˏॱ) {
            dgh.ॱ((Context) this, getString(h.ˊ), "02" + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˊ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˋ);
            ˎ(true);
        } else if (id == o.cst.e.ʽ || id == o.cst.e.ͺ) {
            dgh.ॱ((Context) this, getString(h.ˊ), "03" + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˊ + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + this.ˊˋ);
            ˎ(false);
        } else if (id == o.cst.e.ʼ || id == o.cst.e.ˊॱ) {
            ॱ((Activity) this);
        } else if (id == o.cst.e.ᐝॱ) {
            ˏˏ();
        }
    }

    private void ˏˏ() {
        cjm o_cjm = new cjm("ConsumeRecordActivity.activity", null);
        o_cjm.ॱ().setFlags(268435456);
        cjk.ˎ().ˋ(ContentManager.getInstant().getContext(), o_cjm);
    }

    protected void ah_() {
    }

    protected void ᐝॱ() {
        LinearLayout linearLayout = (LinearLayout) this.ʻॱ.findViewById(o.cst.e.ˊॱ);
        if (csv.ˋ().ˎ()) {
            linearLayout.setVisibility(0);
            ˏ(true);
            return;
        }
        linearLayout.setVisibility(8);
        ˏ(false);
    }

    protected void ʼॱ() {
        if (csv.ˋ().ˎ()) {
            this.ॱˊ.setVisibility(0);
            ˏ(true);
            return;
        }
        this.ॱˊ.setVisibility(8);
        ˏ(false);
    }

    public void ˉ() {
        int ˋ = this.mFixViewPager.getCurrentItem();
        if (ˋ == 1) {
            if (this.ˊᐝ instanceof PurchaseHorizontalMultiTabsFragment) {
                ((PurchaseHorizontalMultiTabsFragment) this.ˊᐝ).ॱʾ();
            }
        } else if (ˋ == 0 && (this.ˋˊ instanceof ProductFragment)) {
            ((ProductFragment) this.ˋˊ).ʼᐝ();
        }
    }

    protected <T> void ˎ(T t) {
        if (dgm.ˎ((Activity) this) == 5) {
            this.ˏॱ = ContentManager.getInstant().getContext().getResources().getString(h.ʽॱ);
        } else {
            this.ˏॱ = ContentManager.getInstant().getContext().getResources().getString(h.ʼॱ);
        }
        this.ˋॱ = ContentManager.getInstant().getContext().getResources().getString(h.ʿ);
        if (t instanceof IPurchaseHistoryProtocol) {
            this.ˍ = ((IPurchaseHistoryProtocol) t).getCurrentPosition();
        }
    }
}
